package com.gz.EuchreU.Controls;

import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.text.Text;
import org.anddev.andengine.input.touch.TouchEvent;

import com.gz.EuchreU.Contants.CardValues;
import com.gz.EuchreU.Contants.GameOptions;
import com.gz.EuchreU.Contants.Suits;
import com.gz.EuchreU.Contants.UI;
import com.gz.EuchreU.Sprite.Card;

public class DifficultyMenu extends MovingMenuEntity{

	private RatingCards mPDiff;
	private Text mPText;
	private RatingCards mOppLeftDiff;
	private Text mOppLeftText;
	private RatingCards mOppRightDiff;
	private Text mOppRightText;
	private Text mAlwaysPassText;
	private Card mAlwaysPass;
	
	public DifficultyMenu(float pOnScreenX, float pOnScreenY, float pWidth,Scene pScene) {
		super(pOnScreenX, pOnScreenY, pWidth, true);

		float cardWidth = pWidth/15;
		float buttonX = pOnScreenX + pWidth/2;
		float buttonY = pOnScreenY + 30;
		float textX = pOnScreenX + pWidth/4 - cardWidth;
			
		mPDiff = new RatingCards(buttonX, buttonY,cardWidth,pScene){
			@Override
			public void OnValueChanged(int pNewValue) {
				GameOptions.SetIntOption(GameOptions.PREF_INT_P_SKILL, pNewValue);	
			}
		};
		float cardHeight = UI.getTextures().getHeightFromWidthTiled(0, 0, cardWidth);
		float textY = buttonY + cardHeight/3;		
		mPText = GetText(textX, textY, "Partner Skill");
		textY += cardHeight + 2;
		buttonY += cardHeight + 2;
		
		mOppLeftDiff = new RatingCards(buttonX, buttonY, cardWidth, pScene){
			@Override
			public void OnValueChanged(int pNewValue) {
				GameOptions.SetIntOption(GameOptions.PREF_INT_O_LEFT_SKILL, pNewValue);
			}
		};
		mOppLeftText = GetText(textX, textY, "Left Opp Skill");
		textY += cardHeight + 2;
		buttonY += cardHeight + 2;
		
		mOppRightDiff = new RatingCards(buttonX, buttonY, cardWidth, pScene){
			@Override
			public void OnValueChanged(int pNewValue) {
				GameOptions.SetIntOption(GameOptions.PREF_INT_O_RIGHT_SKILL, pNewValue);
			}
		};
		mOppRightText = GetText(textX, textY, "Right Opp Skill");

		buttonY += cardHeight + 2;
		textY += cardHeight + 2;
		
		mAlwaysPass = GetAceOfSpades(buttonX, buttonY, cardWidth);
		mAlwaysPassText= GetText(textX, textY, "AI Always Pass");
		
		attachChild(mPDiff);
		attachChild(mPText);
		attachChild(mOppLeftDiff);
		attachChild(mOppLeftText);
		attachChild(mOppRightDiff);
		attachChild(mOppRightText);
		attachChild(mAlwaysPass);
		attachChild(mAlwaysPassText);
		
		pScene.registerTouchArea(mAlwaysPass);
		
		setDefaults();
	}

	private void setDefaults(){
		mPDiff.setValue(GameOptions.GetIntOption(GameOptions.PREF_INT_P_SKILL), false);
		mOppLeftDiff.setValue(GameOptions.GetIntOption(GameOptions.PREF_INT_O_LEFT_SKILL), false);
		mOppRightDiff.setValue(GameOptions.GetIntOption(GameOptions.PREF_INT_O_RIGHT_SKILL), false);
		mAlwaysPass.setDisabled(!GameOptions.GetBoolOption(GameOptions.PREF_BOOL_AI_ALWAYS_PASSES));
	}
	
	@Override
	public Card GetAceOfSpades(final float pX, final float pY, final float pWidth){
		return new Card(pX,pY,pWidth,Suits.SPADES,CardValues.ACE){
			@Override
			public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
					float pTouchAreaLocalX, float pTouchAreaLocalY) {
				if(pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP){		
					
					if(this.getCardID() == mAlwaysPass.getCardID()){
						this.setDisabled(!this.getDisabled());
//						mAlwaysPass.setDisabled(this.getDisabled());
						
//						GameOptions.SetBoolOption(GameOptions.PREF_BOOL_AI_ALWAYS_PASSES, !this.getDisabled());
						GameOptions.SetBoolOption(GameOptions.PREF_BOOL_AI_ALWAYS_PASSES, !mAlwaysPass.getDisabled());
					}
				}
				return true;
			}
		};
	}
	
}
